package com.fept.msgcore.msgserver.protocol.model.option;

import com.fept.msgcore.msgserver.protocol.model.base.ProtocolConstants;

/**
 * Created by Srma on 2/9/2017.
 */
public class AnswerOption extends BaseOption {

    /**
     *
     */
    private static final long serialVersionUID = 6278821598027512146L;

    private int answerWord = ProtocolConstants.ANSWER_OPTION_OK;

    public AnswerOption() {
        this.setType(ProtocolConstants.OPTION_ANSWER);
        this.setLength(1);
    }

    /**
     *
     * @param type
     * @return
     */
    public static AnswerOption getAnswerOption(int type) {
        AnswerOption answerOption = new AnswerOption();
        answerOption.setAnswerWord(type);
        return answerOption;
    }

    /**
     *
     */
    @Override
    public byte[] pack() {
        byte[] optionBytes = new byte[1];
        optionBytes[0] = (byte) (this.answerWord & 0xFF);

        this.setValue(optionBytes);
        this.setLength(optionBytes.length);
        return super.pack();
    }

    /**
     *
     */
    @Override
    public void unpack(byte[] data, int offset) {
        super.unpack(data, offset);

        data = this.getValue();
        offset = 0;

        this.setAnswerWord(data[offset]);
        offset += 1;
    }

    /**
     * @return the answerWord
     */
    public int getAnswerWord() {
        return answerWord;
    }

    /**
     * @param answerWord
     *            the answerWord to set
     */
    public void setAnswerWord(int answerWord) {
        this.answerWord = answerWord;
    }
}
